# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

# Initial PKGBUILD from AUR.
# Old Maintainer: Niklas Krafczyk <krafczyk.n at gmail dot com>

pkgname=klee
pkgver=2.3
pkgrel=5
pkgdesc='A symbolic virtual machine built on top of the LLVM compiler infrastructure.'
arch=('x86_64' 'aarch64')
url='https://github.com/klee/klee'
license=('custom:UIUC')
groups=('blackarch' 'blackarch-binary' 'blackarch-reversing'
        'blackarch-debugger')
depends=('gperftools' 'z3' 'libcap' 'python' 'llvm-libs' 'klee-uclibc' 'sqlite')
makedepends=('llvm' 'clang' 'cmake' 'git' 'gperftools' 'z3')
source=("git+https://github.com/$pkgname/$pkgname.git#commit=879be792870d20a51e26f8f007d24fc0584ee514"
        "git+https://github.com/google/googletest.git#tag=release-1.10.0"
        'KnownLLVMVersionPatch'
        'TargetRegistryPatch')
sha512sums=('SKIP'
            'SKIP'
            'ba101c4203d1f7c51674fdfd08e34e61d18d5e24ba044d65d46e6f0cf63a15eb1ab10050d4b44bf06af179cfe752c7c98cbb096121813b90557b846ce3d9c941'
            'a8e9cc67ea6b62d3fd7c446c7538180ba3cf8a185453ecd857ee0a8be75dec427acd60a39d472c01166b4bfedecfc0478e271becf5bd8b603ccf0d019a56aae3')

prepare() {
  cd $pkgname

  git cherry-pick 39f8069db879e1f859c60c821092452748b4ba37
  git apply "$srcdir/TargetRegistryPatch"
  git apply "$srcdir/KnownLLVMVersionPatch"

  mkdir -p "$srcdir/build"
  cd "$srcdir/build"

  cmake \
    -DENABLE_TCMALLOC=ON \
    -DENABLE_UNIT_TESTS=ON \
    -DENABLE_SYSTEM_TESTS=ON \
    -DENABLE_POSIX_RUNTIME=ON \
    -DENABLE_KLEE_UCLIBC=ON \
    -DKLEE_UCLIBC_PATH=/usr/share/klee-uclibc/usr \
    -DENABLE_SOLVER_Z3=ON \
    -DENABLE_SOLVER_STP=OFF \
    -DENABLE_SOLVER_METASMT=OFF \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=/usr/lib \
    -DCMAKE_BUILD_TYPE=Release \
    -DGTEST_SRC_DIR="$srcdir/googletest/googletest" \
    -DENABLE_UNIT_TESTS=ON \
    -DENABLE_SYSTEM_TESTS=ON \
    "$srcdir/$pkgname"
}

build() {
  cd build

  make $MAKEFLAGS
}

package() {
	cd build

	make DESTDIR="$pkgdir" install

  install -Dm 644 "$srcdir/$pkgname/LICENSE.TXT" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

